

package com.maoshi.shop.distribution.platform.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.maoshi.shop.common.util.PageParam;
import com.maoshi.shop.distribution.comment.model.DistributionUserWallet;
import com.maoshi.shop.distribution.comment.service.DistributionUserWalletService;
import com.maoshi.shop.security.platform.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author lgh on 2019/04/01.
 */
@RestController
@RequestMapping("/distribution/distributionUserWallet")
public class DistributionUserWalletController {

    @Autowired
    private DistributionUserWalletService distributionUserWalletService;

    /**
     * 分页获取
     */
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('admin:distributionUserWallet:page')")
    public ResponseEntity<IPage<DistributionUserWallet>> page(DistributionUserWallet distributionUserWallet, PageParam<DistributionUserWallet> page) {
        IPage<DistributionUserWallet> list = distributionUserWalletService.page(page, new LambdaQueryWrapper<DistributionUserWallet>());
        return ResponseEntity.ok(list);
    }

    /**
     * 分页获取(携带UserVO)
     */
    @GetMapping("/pageAndUser")
    @PreAuthorize("@pms.hasPermission('admin:distributionUserWallet:page')")
    public ResponseEntity<IPage<DistributionUserWallet>> pageAndUser(String userMobile, PageParam<DistributionUserWallet> page) {
        IPage<DistributionUserWallet> list = distributionUserWalletService.getDistributionUserWalletAndDistributionUserVOPage(page, userMobile);
        return ResponseEntity.ok(list);
    }

    /**
     * 获取信息
     */
    @GetMapping("/info/{id}")
    @PreAuthorize("@pms.hasPermission('admin:distributionUserWallet:info')")
    public ResponseEntity<DistributionUserWallet> info(@PathVariable("id") Long id) {
        DistributionUserWallet distributionUserWallet = distributionUserWalletService.getById(id);
        return ResponseEntity.ok(distributionUserWallet);
    }

    /**
     * 保存
     */
    @PostMapping
    @PreAuthorize("@pms.hasPermission('admin:distributionUserWallet:save')")
    public ResponseEntity<Void> save(@RequestBody @Valid DistributionUserWallet distributionUserWallet) {
        distributionUserWalletService.save(distributionUserWallet);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改
     */
    @PutMapping
    @PreAuthorize("@pms.hasPermission('admin:distributionUserWallet:update')")
    public ResponseEntity<Void> update(@RequestBody @Valid DistributionUserWallet distributionUserWallet) {
        distributionUserWalletService.updateDistributionUserWallet(distributionUserWallet, SecurityUtils.getSysUser().getUserId());
        return ResponseEntity.ok().build();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('admin:distributionUserWallet:delete')")
    public ResponseEntity<Void> delete(@PathVariable Long id) {
        distributionUserWalletService.removeById(id);
        return ResponseEntity.ok().build();
    }
}
